package com.dede.getmusic.module.home

import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.TextView
import com.dede.getmusic.R
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import org.jetbrains.anko.backgroundDrawable
import org.jetbrains.anko.dip
import org.jetbrains.anko.textColor

/**
 * @author hsh
 * @date 2017/10/16 13:47.
 * @doc
 */
class SearchHisAdapter(val context: Context, data: List<String>) : TagAdapter<String>(data) {

    private val color by lazy { ContextCompat.getColor(context, R.color.colorAccent) }

    override fun getView(parent: FlowLayout, position: Int, t: String?): View {
        val textView = TextView(context)
        textView.textColor = color
        textView.text = t
        textView.textSize = 13f
        textView.setPadding(context.dip(8), context.dip(1.5f),
                context.dip(8), context.dip(1.5f))
        val drawable = GradientDrawable()
        drawable.setStroke(context.dip(1.1f), color)
        drawable.cornerRadius = context.dip(15).toFloat()
        textView.backgroundDrawable = drawable
        return textView
    }
}